<?php
	$routes         = require_once 'core/routes.php';
	$configuration  = require_once 'core/configuration.php';
	$url_routes     = array();

	session_start();

	// Almacena mensajes informativos.
	if (empty($_SESSION['messages']))
		$_SESSION['messages'] = array();

	// Genera la URL completa de las rutas.
	foreach ($routes as $route => $component)
		$url_routes[$route] =  $configuration['url'] . 'index.php?page=' . $component['route'];

	// Obtine el controlador y la vista de la página solicitada.
	if (!empty($_GET['page'])) {
		foreach ($routes as $route => $component)
			if ($component['route'] == $_GET['page']) {
				$controller = $component['controller'];
				$view       = $component['view'];
				break;
			}
	}

	// Renderiza la vista de una página web.
	if (empty($controller) || empty($view)) {
		header('Location: ' . $url_routes['home']);

		exit;
	}

	require_once 'controllers/' . $controller . '.php';

	$object = new $controller();
	$object -> $view();